Hello and welcome back to our costs.
Soon the last session we learned that India raised containers of homogeneous data.
So in particular for numerical data.
And this allows us to make fast element Weiss and vector rise operations.
So far we have only seen one dimensional arrays are only one sequence of elements and in linear algebra.
You would call it a vector.
And this is only a special case of India race and the general case is a multi-dimensional array.
And in the case of two dimensions.
Yeah you and Linnea argue probably would call it a matrix and the matrix S rows and columns and the
amount of elements in the row.
So if you count the number of elements from left to right is the size of a row and the amount of elements
in a column.
So we account the elements from top to the bottom is the size of the column and the size of each of
those dimensions.
Give us the shape so for example we have three rows and four columns.
But now let's stop coding so we important umpires and P as always.
Then we create a num pi array from one to twelve including and we can check the type.
So should be an end the array and then we can check the shape of our end the array.
So by calling the attribute shape and here you can see it's a one dimensional array so we have only
one dimension here.
If we had to ask me I mentioned c what if.
Yeah two or three numbers here it's a one dimensional array containing of twelve elements in linear
algebra.
You would call it a vector of its elements.
And what we got now can do we can reshape our ending array with the method.
Dot reshape and then we can determine how the shape should look like the first position determines the
amount of rows and the second position determines the amount of columns.
Yeah we want transform our one dimensional array with both elements into an array with two rows and
each row has six columns.
So let's run the cell and let's have a look at a funny you can see Python returns us a two dimensional
array.
So we have here an outer array and this is containing two arrays so two rows here in this example.
So we have the first row and the second row and each row has six columns.
And we can also check now on the shape of our new two dimensional array.
And it's no surprise two and six so two rows six columns of course we can also reshape our array to
the shape six rows and two columns.
Also here with the reshape method.
So now you can see we get six rows and each row containing two elements.
So we have six rows and two columns and let's also check the shape it's six rows and two columns an
element y's operations or vector US operations still work in the same manner as with only a one dimensional
array.
So that's no problem.
So if we add hundreds to a we at 100 to each element of our array.
So before we add Tier 1 2 in the first row now we have 101 and 102 and so on.
So now let's remind that we have in total twelve elements in our array.
And she tried to reshape our array let's say into regrowth and five columns.
So that would mean 15 elements.
This does not work and pass and tests cannot reshape array of size twelve and to shape 3 5.
And we are not limited to two dimensions so we can increase the amount of dimensions to let's say 3.
So we can say okay we want to reshape the end the array and create a three dimensional array.
So the first dimension is the size of two.
The second is the size of two and the third dimension has to the size of three.
So it's kind of a cube.
So now you can see here this is the first element of the first dimension and this is the second element
of the first dimension so the first dimension contains two times the matrix consisting of two rows and
three columns.
So let's check the shape of a.
And we get the shape as a three dimensional with the size 2 2 and 3.
So now let's assume we want to create a two dimensional array containing of the numbers 1 to 100 including
in the shape 25 rows and 4 columns.
We can do that in our 1 line of code.
So first of all we create a one dimensional array consisting of the numbers 1 2 100 and then we reshape
the array and get 25 rows and 4 columns.
So let's see what we get.
So now we have field twenty five rows and four columns and our elements and immigrated from 1 to 100.
All right.
So this was the introduction to multi-dimensional arrays and they are and the next session you will
have a look how to index and slice multi-dimensional arrays.
So hope you are it and see you in the next session by.